package com.eidos.blogs.openapi.service.seckill.impl;

import com.eidos.blogs.openapi.entity.seckill.RedeReceiveSyncRecords;
import com.eidos.blogs.openapi.exception.SourceException;
import com.eidos.blogs.openapi.rest.QueryParams;
import com.eidos.blogs.openapi.mapper.seckill.RedeReceiveSyncRecordsMapper;
import com.eidos.blogs.openapi.service.seckill.IRedeReceiveSyncRecordsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ： Eidos
 * @date ：Created in 2021-01-12
 * @description：领取红包过程表 服务实现类
 * @modified By：
 * @version: 1.0
 */
@Service
public class RedeReceiveSyncRecordsServiceImpl extends ServiceImpl<RedeReceiveSyncRecordsMapper, RedeReceiveSyncRecords> implements IRedeReceiveSyncRecordsService {


    /**
     * 领取红包过程表分页列表
     *
     * @param param 根据需要进行传值
     * @return
     */
    @Override
    public IPage<RedeReceiveSyncRecords> page(RedeReceiveSyncRecords param) {
        Page page = QueryParams.getPage();
        QueryWrapper<RedeReceiveSyncRecords> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                // 自增主键
                .eq(param.getId() != null, RedeReceiveSyncRecords::getId, param.getId())
                // 红包唯一ID
                .eq(param.getRedEnvelopeId() != null, RedeReceiveSyncRecords::getRedEnvelopeId, param.getRedEnvelopeId())
                // 红包金额单位分
                .eq(param.getRestAmount() != null, RedeReceiveSyncRecords::getRestAmount, param.getRestAmount())
                // 红包个数
                .eq(param.getRestNum() != null, RedeReceiveSyncRecords::getRestNum, param.getRestNum())
                // 创建时间
                .eq(param.getCreateTime() != null, RedeReceiveSyncRecords::getCreateTime, param.getCreateTime())
        ;
        return baseMapper.selectPage(page, wrapper);
    }

    /**
     * 领取红包过程表详情
     *
     * @param id
     * @return
     */
    @Override
    public RedeReceiveSyncRecords info(Long id) {
        return getById(id);
    }

    /**
     * 领取红包过程表新增
     *
     * @param param 根据需要进行传值
     * @return
     */
    @Override
    public void add(RedeReceiveSyncRecords param) {
        if (!save(param)) {
            throw new SourceException("新增失败");
        }
    }

    /**
     * 领取红包过程表修改
     *
     * @param param 根据需要进行传值
     * @return
     */
    @Override
    public void modify(RedeReceiveSyncRecords param) {
        if (!updateById(param)) {
            throw new SourceException("保存失败");
        }
    }

    /**
     * 领取红包过程表删除(单个条目)
     *
     * @param id
     * @return
     */
    @Override
    public void remove(Long id) {
        removeById(id);
    }

    /**
     * 领取红包过程表删除(多个条目)
     *
     * @param ids
     * @return
     */
    @Override
    public void removes(List<Long> ids) {
        removeByIds(ids);
    }
}
